<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
services:
<%_ for(let i = 0; i < appConfigs.length; i++) { _%>
<%- appsYaml[i] %>
<%_ } _%>
<%_ if (useKafka) { _%>
  kafka:
    image: <%- dockerContainers.kafka %>
    environment:
      KAFKA_NODE_ID: 1
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://localhost:9093
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      #ports:
      # - 9092:9092 # Uncomment to make Kafka available externally
<%_ } _%>
<%_ if (usePulsar) { _%>
  pulsar:
    image: <%- dockerContainers.pulsar %>
    environment:
      PULSAR_MEM: ' -Xms512m -Xmx512m -XX:MaxDirectMemorySize=1g'
    command: bin/pulsar standalone
    #ports:
    # - 6650:6650 # Uncomment to make Pulsar available externally
    # - 8080:8080
<%_ } _%>
<%_ if (serviceDiscoveryEureka) { _%>
  jhipster-registry:
    image: <%- dockerContainers.jhipsterRegistry %>
    volumes:
      - ./central-server-config:/central-config
    # By default the JHipster Registry runs with the "dev" and "native"
    # Spring profiles.
    # "native" profile means the filesystem is used to store data, see
    # http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=dev<% if (usesOauth2) { %>,oauth2<% } %>
      - SPRING_SECURITY_USER_PASSWORD=<%= adminPassword %>
      - JHIPSTER_REGISTRY_PASSWORD=<%= adminPassword %>
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/jhipster/jhipster-registry/
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
  <%_ if (monitoringElk) { _%>
      - JHIPSTER_LOGGING_LOGSTASH_ENABLED=true
      - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
  <%_ } _%>
  <%_ if (monitoringPrometheus) { _%>
      - MANAGEMENT_PROMETHEUS_METRICS_EXPORT_ENABLED=true
  <%_ } _%>
  <%_ if (usesOauth2) { _%>
      # For Keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/realms/jhipster
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
    depends_on:
      keycloak:
        condition: 'service_healthy'
  <%_ } _%>
    ports:
      - 8761:8761
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8761/management/health"]
      interval: 5s
      timeout: 5s
      retries: 10
<%_ } _%>
<%_ if (serviceDiscoveryConsul) { _%>
  consul:
    image: <%- dockerContainers.consul %>
    ports:
      - 8300:8300
      - 8500:8500
      - 8600:8600
    command: consul agent -dev -ui -client 0.0.0.0 -log-level=INFO
  consul-config-loader:
    image: <%- dockerContainers.consulConfigLoader %>
    volumes:
      - ./central-server-config:/config
    environment:
      - INIT_SLEEP_SECONDS=5
      - CONSUL_URL=consul
      - CONSUL_PORT=8500
<%_ } _%>
<%_ if (usesOauth2) { _%>
  keycloak:
    image: <%- dockerContainers.keycloak %>
    command: 'start-dev --import-realm'
    volumes:
      - ./realm-config:/opt/keycloak/data/import
      - ./realm-config/keycloak-health-check.sh:/opt/keycloak/health-check.sh
    environment:
      - KC_DB=dev-file
      - KC_BOOTSTRAP_ADMIN_USERNAME=admin
      - KC_BOOTSTRAP_ADMIN_PASSWORD=admin
      - KC_FEATURES=scripts
      - KC_HTTP_PORT=9080
      - KC_HTTPS_PORT=9443
      - KC_HEALTH_ENABLED=true
      - KC_HTTP_MANAGEMENT_PORT=9990
    ports:
      - 9080:9080
      - 9443:9443
    healthcheck:
      test: 'bash /opt/keycloak/health-check.sh'
      interval: 5s
      timeout: 5s
      retries: 20
<%_ } _%>
<%_ if (monitoringPrometheus) { _%>

  prometheus:
    image: <%- dockerContainers.prometheus %>
    volumes:
      - ./prometheus-conf/:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
      - 9090:9090
  alertmanager:
    image: <%- dockerContainers.prometheusAlertmanager %>
    ports:
      - 9093:9093
    volumes:
      - ./alertmanager-conf/:/etc/alertmanager/
    command:
      - '--config.file=/etc/alertmanager/config.yml'
      - '--storage.path=/alertmanager'

  grafana:
    image: <%- dockerContainers.grafana %>
    ports:
      - 3000:3000
    volumes:
      - grafana_data:/var/lib/grafana
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_USERS_ALLOW_SIGN_UP=false

volumes:
  prometheus_data: {}
  grafana_data: {}
<%_ } _%>
